# xnvme_file completion                           -*- shell-script -*-
#
# Bash completion script for the `xnvme_file` CLI
#
# SPDX-FileCopyrightText: Samsung Electronics Co., Ltd
#
# SPDX-License-Identifier: BSD-3-Clause

_xnvme_file_completions()
{
    local cur=${COMP_WORDS[COMP_CWORD]}
    local sub=""
    local opts=""

    COMPREPLY=()

    # Complete sub-commands
    if [[ $COMP_CWORD < 2 ]]; then
        COMPREPLY+=( $( compgen -W 'write-read dump-sync dump-sync-iovec dump-async dump-async-iovec load-sync load-async copy-sync copy-async --help' -- $cur ) )
        return 0
    fi

    # Complete sub-command arguments

    sub=${COMP_WORDS[1]}

    if [[ "$sub" != "enum" ]]; then
        opts+="/dev/nvme* "
    fi

    case "$sub" in
    
    "write-read")
        opts+="--help"
        ;;

    "dump-sync")
        opts+="--data-nbytes --iosize --direct --help"
        ;;

    "dump-sync-iovec")
        opts+="--data-nbytes --iosize --direct --sync --be --vec-cnt --help"
        ;;

    "dump-async")
        opts+="--data-nbytes --iosize --qdepth --direct --help"
        ;;

    "dump-async-iovec")
        opts+="--data-nbytes --iosize --qdepth --direct --async --be --vec-cnt --help"
        ;;

    "load-sync")
        opts+="--iosize --direct --help"
        ;;

    "load-async")
        opts+="--iosize --qdepth --direct --help"
        ;;

    "copy-sync")
        opts+="--iosize --direct --help"
        ;;

    "copy-async")
        opts+="--iosize --qdepth --direct --help"
        ;;

    esac

    COMPREPLY+=( $( compgen -W "$opts" -- $cur ) )

    return 0
}

#
complete -o nosort -F _xnvme_file_completions xnvme_file

# ex: filetype=sh
